package eg.ci.mvn.service.demo.mq.receiver;

import eg.ci.mvn.service.core.config.rabbitmq.MqConfig;
import eg.ci.mvn.service.core.config.rabbitmq.MqTestRabbitFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


@Slf4j
@Component
@ConditionalOnBean(value = RabbitAdmin.class, name = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
public class MqReceiverService {

    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_FANOUT_1,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqFanout1(String request) {

    }

    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_FANOUT_2,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqFanout2(String request) {

    }

    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_DIRECT_1,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqDirect1(String request) {

    }

    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_DIRECT_2,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqDirect2(String request) {

    }



    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_TOPIC_1,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqTopic1(String request) {
        log.info("{} 收到消息 工作 3 秒后返回 === {}", "processMqTopic1",request);
    }

    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_TOPIC_2,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqTopic2(String request) {
        log.info("{} 收消息 工作 3 秒后返回  === {}", "processMqTopic2", request);
    }


    @RabbitListener(containerFactory = MqTestRabbitFactory.BEAN_NAME_RABBIT_LISTENER_CONTAINER_FACTORY,
            queues = MqConfig.QUEUE_TEST_TOPIC_ALL,
            admin = MqTestRabbitFactory.BEAN_NAME_RABBIT_ADMIN)
    @Transactional(rollbackFor = Exception.class)
    public void processMqTopicAll(String request) {
        log.info("{} 收消息 工作 3 秒后返回  === {}", "processMqTopicAll", request);
    }
}
